#include "StdAfx.h"
#include "GeomImporter.h"
#include "GeomLoaderFactory.h"

#include "../shared/StringUtil.h"

GeomImporter::GeomImporter(void)
{
}

GeomImporter::~GeomImporter(void)
{
}

/** Create a new Map */
IGeom* GeomImporter::CreateGeom( const std::string &fileName )
{
    GeomLoaderFactory factory;
    IGeomLoader* loader = factory.CreateGeomLoader( FindGeomType( fileName ) );

    IGeom* Geom = NULL;
    if ( loader )
    {
        Geom = loader->LoadGeom( fileName );
        if ( Geom )
            Geom->Init();
        
        delete loader;      // free the loader
    }

    return Geom;
}

/** Find the type of map the file is */
Geom_t GeomImporter::FindGeomType( const std::string &fileName )
{
    std::string ext = StringUtil::ToLower( GetFileExtension( fileName ) );
    if ( ext == "bsp" )
        return GF_BSP;
    else if ( ext == "irr" )
        return GF_IRR;
    else
        return GF_UNKNOWN;
}